package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("adminShopController")
@Api(tags = "店铺管理接口")
@RequestMapping("/admin/shop")
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    private static final String key = "SHOP_STATUS";
    /**
     * 店铺营业状态设置
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    public Result statusController(@PathVariable Integer status){
        log.info("店铺营业状态设置为：{}",status == 1 ? "营业中" : "打样中");
        redisTemplate.opsForValue().set(key,status);
        return Result.success();
    }

    /**
     * 店铺状态查询
     * @return
     */
    @GetMapping("/status")
    public Result<Integer> statusCheck(){
        Integer status = (Integer) redisTemplate.opsForValue().get(key);
        log.info("店铺营业状态设置为：{}",status == 1 ? "营业中" : "打样中");
        return Result.success(status);
    }

}
